package com.poqop.document;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;

import java.io.File;
import java.io.FileFilter;
import java.util.HashMap;

import org.vudroid.pdfdroid.PdfViewerActivity;

/**
 * 浏览文件
 * 
 * @author SF-6280
 * 
 */
public class MainBrowserActivity extends BaseBrowserActivity {
	private final static HashMap<String, Class<? extends Activity>> extensionToActivity = new HashMap<String, Class<? extends Activity>>();

	static {
		extensionToActivity.put("pdf", PdfViewerActivity.class);
		/*
		 * extensionToActivity.put("djvu", DjvuViewerActivity.class);
		 * extensionToActivity.put("djv", DjvuViewerActivity.class);
		 */
	}

	@Override
	protected FileFilter createFileFilter() {
		return new FileFilter() {
			public boolean accept(File pathname) {
				for (String s : extensionToActivity.keySet()) {
					if (pathname.getName().endsWith("." + s)) {
						return true;
					}
				}
				return pathname.isDirectory();
			}
		};
	}

	@Override
	protected void showDocument(Uri uri) {
		final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		String uriString = uri.toString();
		String extension = uriString.substring(uriString.lastIndexOf('.') + 1);
		intent.setClass(this, extensionToActivity.get(extension));
		startActivity(intent);
	}
}
